<?php
use yii\widgets\ActiveForm;
use yii\helpers\Html;
use doumiaoduo\layer\LayerAsset;
$cash = 0;
$p_cash = 0;
$p_name = '';
if(isset($account)){

    if($account->cash >0){
        if($account->cash > $model->total_amount)
         $cash = $model->total_amount-$p_cash;
        else
         $cash =  $account->cash;
    }
}

?>
<div class="yx-cnt-box yx-praise-content yx-radius2">
    <div class="yx-praise-box">
        <?php $form = ActiveForm::begin(['enableAjaxValidation' => true,'enableClientValidation' => false,'options'=>['class'=>'form-validate']]); ?>
        <table id="data-load" class="yx-course-info" >
                <tr>
                    <td>订单总金额：</td>
                    <td><?=$model->total_amount?></td>
                </tr>
                <?php if($goods->category_id == 1) {?>
                    <?php if($account->puzzle_cash > 0) { ?>
                        <tr>
                            <td>益智类金额：</td>
                            <td>
                               <?=Html::checkbox('type_cash',false,['data-type'=>'puzzle_cash'])?> <?=($account)?$account->puzzle_cash:0?></td>
                        </tr>
                    <?php } ?>
            <?php } ?>
            <?php if($goods->category_id == 2) {?>
               <?php if($account->music_cash > 0) { ?>
                    <tr>
                        <td>音乐类金额：</td>
                        <td>
                            <?=Html::checkbox('type_cash',false,['data-type'=>'music_cash'])?><?=($account)?$account->music_cash:0?></td>
                    </tr>
                <?php } ?>
            <?php } ?>
            <?php if($goods->category_id == 3) {?>
               <?php if($account->body_cash > 0) { ?>
                    <tr>
                        <td>形体类金额：</td>
                        <td>
                            <?=Html::checkbox('type_cash',false,['data-type'=>'body_cash'])?> <?=($account)?$account->body_cash:0?></td>
                    </tr>
                <?php } ?>
            <?php } ?>
                <tr>
                    <td>账户余额：</td>
                    <td><?php if(isset($account) && $account->cash >0) {?><?= \yii\helpers\Html::checkbox('cash',true,['data'=>['type'=>'cashs'], 'value'=>isset($account)?$account->cash:0,'class'=>'input-radiolist','style'=>'display:none'])?><?php }?><?=isset($account)?$account->cash:0?></td>
                </tr>
                <tr>
                    <td>支付密码：</td>
                    <td><?=$form->field($AccountRecord,'pay_password',['template' => '{input}{error}{hint}'])->passwordInput(['style' => 'width:180px', 'class' => 'input-text'])?></td>
                </tr>
                <tr>
                    <td>总计：</td>
                    <td id="final_amount">
                        <?php if($cash > 0){?>
                            扣除余额:<?=number_format($cash,2)?> <br>
                         <?php } ?>
                        <?php if(($model->total_amount - ($p_cash+$cash)) > 0) {?>
                            需支付现金：<?=number_format((int)($model->total_amount-$cash-$p_cash),2) ?>
                        <?php } ?>
                    </td>
                </tr>
           <tbody id="paymethod" style="display: <?php if($model->total_amount-$cash >0) echo ''; else echo 'none'?>">
            <tr>
                 <td>现金支付</td>
                <td><?=$form->field($AccountRecord,'pay_cash',['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text'])?></td>
            </tr>
            <tr>
                <td>微信支付</td>
                <td><?=$form->field($AccountRecord,'pay_wxpay',['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text'])?></td>
            </tr>
            <tr>
                <td>支付宝支付</td>
                <td><?=$form->field($AccountRecord,'pay_alipay',['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text'])?></td>
            </tr>
            <tr>
                <td>刷卡支付</td>
                <td><?=$form->field($AccountRecord,'pay_card',['template' => '{input}{error}{hint}'])->textInput(['style' => 'width:180px', 'class' => 'input-text'])?></td>
            </tr>
            <tr style="display: none">
                <td></td>
                <td><?=$form->field($AccountRecord,'cash',['template' => '{input}{error}{hint}'])->hiddenInput(['style' => 'width:180px', 'class' => 'input-text','value'=>$cash])?></td>
            </tr>
            <tr style="display: none">
                <td></td>
                <td><?=$form->field($AccountRecord,'p_cash',['template' => '{input}{error}{hint}'])->hiddenInput(['style' => 'width:180px', 'class' => 'input-text','value'=>$p_cash])?></td>
            </tr>
            <tr style="display: none">
                <td></td>
                <td><?=$form->field($AccountRecord,'money',['template' => '{input}{error}{hint}'])->hiddenInput(['style' => 'width:180px', 'class' => 'input-text','value'=>$model->total_amount-$cash])?></td>
            </tr>
           </tbody>
            </table>
            <?=Html::hiddenInput('order_id',$model->id,['id'=>'order_id'])?>
            <?=Html::hiddenInput('customer_id',$model->customer_id,['id'=>'customer_id'])?>
            <?=Html::hiddenInput('discount_type',null,['id'=>'discount_type'])?>
        <div class="m_top_10 btn" style="width: 100%"><?= Html::submitButton('提交', ['id' => 'dosubmit']) ?></div>
        <?php ActiveForm::end(); ?>
    </div>
</div>
<?php
LayerAsset::register($this);
$js=<<<JS

    $('input[type="checkbox"]').change(function(){
        var val = $(this).val();
        var checked = 0;
        if($(this).is(':checked'))
           checked = 1;
          
         var order_id = $('#order_id').val();  
         var customer_id = $('#customer_id').val();
         var types = $(this).data('type');
         if(val > 0){
            $.ajax({
                 url:'/customer-parcash',
                 type:'post',
                 data:{order_id:order_id,customer_id:customer_id,checked:checked,type:types},
                 success:function(data){
                     if(data.status == 1){
                         $('#final_amount').html(data.content);
                         var item = data.data;
                         $('#accountrecord-cash').val(item.cash);
                         $('#accountrecord-p_cash').val(item.type_cash);
                         $('#accountrecord-money').val(item.money);
                         if(item.money > 0){
                           $('#paymethod').show();
                         }else{
                             $('#paymethod').css('display','none');
                         }  
                     }
                   
                    
                     
                 }
            });
        }     
    });
   
JS;
\Yii::$app->view->registerJs($js);
?>
